package com.deer.wms.instock.service.enter;

import com.deer.wms.ASN.manage.model.asn.AsnDetail;
import com.deer.wms.ASN.manage.model.asn.AsnMaster;
import com.deer.wms.instock.model.erpType.ErpType;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: xu
 * @Date: 2022/06/17/11:46
 * @Description:
 */
@Component
public class StrategyEnterService implements ApplicationContextAware {
    private Map<ErpType, AbstractEnterErp> iFileStrategyMap = new ConcurrentHashMap<>();

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Map<String, AbstractEnterErp> tmepMap = applicationContext.getBeansOfType(AbstractEnterErp.class);
        tmepMap.values().forEach(strategyService -> iFileStrategyMap.put(strategyService.gainType(), strategyService));
    }


    public Map<String,String> resolveAsn(AsnMaster asnMaster, List<AsnDetail> asnDetail) {
        ErpType erpType = new ErpType(asnMaster.getBillType(), asnMaster.getAsnType());
        AbstractEnterErp abstractEnterErp = iFileStrategyMap.get(erpType);
        if (abstractEnterErp != null) {
            abstractEnterErp.sendERP(asnMaster, asnDetail);
        }

        return null;
    }

}
